<?	
	//define('IN_SITE', true);
	$ids = isset($_REQUEST['ids'])? $_REQUEST['ids'] : session_id() ;
	$lng = isset($_REQUEST['lang'])? $_REQUEST['lang'] : 'us' ;
	
	$url=$_SERVER['HTTP_HOST'].$_SERVER['QUERY_STRING']; 
	if (eregi("products.php",$url)) {	
		die("&nbsp;");
	}
	$template_products_body="template/product_list.tpl";
	$template_sub_cat="template/subcat.tpl";
	$base_url 	= 'index.php';
	
	$url= substr($url,strpos($url,".php"),strlen($url));
	$url=explode("/",$url);
	$mode=$url[2] ; 
	 
	 switch($mode){ 
		  case "catalogs":
			  viewcaTsub();
			  break;
		  default:
			  viewProduct(); 
			  break;	 
	 }
function viewProduct(){
	global $template,$db,$template_products_body,$base_url,$url,$site_base_href,$act,$langUrl,$ids;
	
	$start		= isset($url[5]) ? intval($url[5]) : 0;
	$txtgoto=isset($_POST['txtgoto']) ? intval($_POST['txtgoto']) : 0;
		
	$perPageItem = isset($_POST["perPageItem"]) ? intval($_POST["perPageItem"]) : (isset($url[3]) ? intval($url[3]) : 0);
	$optContry  =isset($_POST["optContry"]) ? intval($_POST["optContry"]) : (isset($url[4]) ? intval($url[4]) : 0);
	$CatID 		=$url[2];
  
	$display=!empty($perPageItem) ? intval($perPageItem) :10;
	 if($txtgoto){
		//$start	=  floor($txtgoto*$display)-1; 
		$start	=  floor(($txtgoto-1)*$display); 		
	}
	
	 
	$sql.=" order by memLevel DESC,Keywords ASC limit $start,$display";
	if(!$result=$db->sql_query($sql)){ 	message_die("Couldn't run the sql query!!!1","",__LINE__,__FILE__,$sql);	}
	$pro_count=$db->sql_numrows($result);
	$pro_data=$db->sql_fetchrowset($result);	
	if($pro_count>0){
		$sql = 'SELECT count(proID) AS total FROM vb_products inner join vb_memberprofile on vb_products.memID= vb_memberprofile.memID where proActive=1 and catID='.$CatID;
		if($optContry){		$sql.=" and Zip=".$optContry;		}
		if ( !$result = $db->sql_query($sql) ) {	message_die("Couldn't run the sql query!!!2", __LINE__, __FILE__, $sql);	}
		$total = $db->sql_fetchrow($result);	 
	}
	$pagination = pagination($site_base_href."/".$base_url."?/manufacturers/".$CatID."/".$perPageItem."/".$optContry , $total['total'], $display, $start, 'start', 'Page ' . '@<img src="'.$site_base_href.'/images/prev.gif" border="0">@<img src="'.$site_base_href.'/images/next.gif" border="0">')."&nbsp;";	
	$total_pages = ceil($total['total']/$display);
	$db->sql_freeresult($result);
		for ($i=0; $i<$pro_count; $i++){	
			$simages='<img src="'.$site_base_href.'/products/'.$pro_data[$i]["sImages"].'" border="0" class="imageborder">';
			if(!ereg(".jpg",$pro_data[$i]["sImages"]) && !ereg(".gif",$pro_data[$i]["sImages"]) ){
			 	$simages='<img src="'.$site_base_href.'/images/no_photo.gif" border="0" class="imageborder">';
			}
			$template->assign_block_vars("productList", array(							
				'pName'	 => '<a href="'.$site_base_href.'/supplier.php?supplier='.$pro_data[$i]["memID"].'&act=products&mode=productDetail&pid='.$pro_data[$i]["proID"] .'&catID='.$pro_data[$i]["catID"].'&ids='.$ids.'&lang=us" class="proLink" target="_blank">'.$pro_data[$i]["ProductName"].'</a>',			 
			 	'pModel'	=> !empty($pro_data[$i]["Model"]) ? 'Model : '. $pro_data[$i]["Model"].'  <br>   ' : '',
				'Contact'	=>'<a href="'.$site_base_href.'/supplier.php?supplier='.$pro_data[$i]["memID"].'&ids='.$ids.'&lang=us" class="proLink" target="_blank">'.$pro_data[$i]["CompanyName"].'</a>',
				'GoldSupplier'	=>	$pro_data[$i]["City"].", ".getContry($pro_data[$i]["countryID"]),
				'photo'		 => '<a href="'.$site_base_href.'/supplier.php?supplier='.$pro_data[$i]["memID"].'&act=products&mode=productDetail&pid='.$pro_data[$i]["proID"] .'&catID='.$pro_data[$i]["catID"].'&ids='.$ids.'&lang=us" class="lMenu" target="_bank">'.$simages.'</a>' ,
				'CHECKBOX'	 => '<input type="Checkbox" name="proid['.$pro_data[$i]["proID"].']" value="'. $pro_data[$i]["proID"] .'" />',
			));
	  }

	getState1($CatID);
	$template->assign_vars(array(		
		'a_action'  => $site_base_href.'/'.$base_url.'?/contacts/&ids='.$ids.'&lang=us',
		'NAVIGATOR' => $pagination,		 
		'NumPage_value' => $display,
		'f_action'	=>$site_base_href.'/'.$base_url.'?ids='.$ids.'&lang=us&/'.$act."/".$CatID,
		'subcat' 	=>getSubTitle($CatID),
		'NOPRO' 	=> !$pro_count ? 'There are no product in this category' : '',
		'block'  	=> !$pro_count ? 'none' : 'display',
		'url'		=>$site_base_href.'/',
		'navidis'  	=> $total_pages>1? 'display' : 'none',
		'g_action' 	=>$site_base_href.'/'.$base_url.'?ids='.$ids.'&lang=us&/'.$act."/".$CatID,
		'maintitle'	=>getSubTitle($CatID,1).' | YellowPages.vn',
		'oldurl' 	=>$langUrl
	));	
				
	$template->set_filenames(array(	"body"	=> $template_products_body	));
	$template->pparse('body');
	$template->destroy();
	$proName=array();	
	$images=array();	
	$proModel=array();	
	$pro_data=array();
}
?>		